package com.web.music.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.web.music.interfaces.PersistenceHelper;
import com.web.music.interfaces.AlbumService;
import com.web.music.model.PersistentEntity;
import com.web.music.model.Album;

@Transactional
public class AlbumServiceImpl implements AlbumService {
	
	private PersistenceHelper persistence;
	
	public void save(Album album) {
		persistence.save(album);
	}

	public List<Album> findAll() {
		List<PersistentEntity> all = persistence.findAll(Album.class);
		List<Album> albums = new ArrayList<Album>(); 
		for (PersistentEntity e: all){
			albums.add((Album)e);
		}
		return albums; 
	}
	
	public Album getById(Long id) {
		return (Album)persistence.getById(Album.class, id);
	}

	public PersistenceHelper getPersistence() {
		return persistence;
	}

	public void setPersistence(PersistenceHelper persistence) {
		this.persistence = persistence;
	}
}